package org.jeecg.modules.wlhy.walletcfg.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.util.PasswordUtil;
import org.jeecg.modules.wlhy.walletcfg.entity.HyWalletCfg;
import org.jeecg.modules.wlhy.walletcfg.mapper.HyWalletCfgMapper;
import org.jeecg.modules.wlhy.walletcfg.service.IHyWalletCfgService;
import org.springframework.stereotype.Service;

/**
 * @Description: 用户钱包密码服务
 * @Author: jeecg-boot
 * @Date:   2022-03-11
 * @Version: V1.0
 */
@Service
public class HyWalletCfgServiceImpl extends ServiceImpl<HyWalletCfgMapper, HyWalletCfg> implements IHyWalletCfgService {


    @Override
    public boolean checkPwd(String pwd, String uid) {
        HyWalletCfg cfg = this.lambdaQuery().eq(HyWalletCfg::getUid, uid).one();
        if (ObjectUtil.isNotEmpty(cfg)) {
            String encryptPayPwd = PasswordUtil.encrypt(cfg.getUid(), pwd, PasswordUtil.BSalt);
            if (StringUtils.equals(encryptPayPwd, cfg.getPwd())) {
                return true;
            }
        }
        return false;
    }
}
